package com.jcl.recruit.log.mapper;

import com.jcl.recruit.log.model.ResumeLog;
import com.jcl.recruit.mapper.SqlMapper;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface ResumeLogMapper extends SqlMapper {

    @Select({
            "select * from resume_log  where resume_id = #{resumeId} order by create_time desc "
    })
    List<ResumeLog> findList(@Param("resumeId") Integer resumeId);

    @Select({
            "<script>",
            "select * from resume_log",
            "<where>",
            "<if test=\"null!=corpCode\">",
            "and corp_code = #{corpCode}",
            "</if>",
            "<if test=\"null!=userId\">",
            "and user_id = #{userId}",
            "</if>",
            "<if test=\"null!=category\">",
            "and category = #{category}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<ResumeLog> findListByCorp(@Param("corpCode") String corpCode,
                                   @Param("userId") Integer userId,
                                   @Param("category") Integer category);

    @Select({
            "<script>",
            "select * from resume_log",
            "<where>",
            "<if test=\"null!=corpCode\">",
            "and corp_code = #{corpCode}",
            "</if>",
            "<if test=\"null!=userId\">",
            "and user_id = #{userId}",
            "</if>",
            "<if test=\"null!=resumeId\">",
            "and resume_id = #{resumeId}",
            "</if>",
            "<if test=\"null!=category\">",
            "and category = #{category}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<ResumeLog> findListByCorpAndResume(@Param("corpCode") String corpCode,
                                            @Param("userId") Integer userId,
                                            @Param("resumeId") Integer resumeId,
                                            @Param("category") Integer category);

    @InsertProvider(type = ResumeLogProvider.class, method = "insertSelective")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ResumeLog record);

}
